package handlers

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
	"swu.com/80p/internal/dbs"
)

// 获取列表接口的 Gin Handler
func GetListHandler(c *gin.Context) {
	tableName := c.Param("tableName")
	if tableName == "" {
		c.JSON(http.StatusBadRequest, gin.H{"error": "Table name is required"})
		return
	}

	var results []map[string]interface{}
	if err := dbs.GetDB().Table(tableName).Find(&results).Error; err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Database error: %v", err)})
		return
	}

	c.JSON(http.StatusOK, results)
}
